<?php


// Check if homepage
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );
$config = SystemSite::getSiteConfig();

if(SystemSite::isFrontEnd()) {
	// Check application current run. If this is not homepage, users and confirm over 18 page and use wasnot login, redirect it to reg page:)
	if(SysRequest::application() != $config->defaultApp && SysRequest::application() != 'confirm' && SysRequest::application() != 'authenticate' && SysRequest::application() != 'privacy') {
		
		// Make sure ignore application user and task is register
	//	if(SysRequest::application() != 'users' || ( SysRequest::application() != 'users' && SysRequest::action() != 'register')) {
	//		// Check if not login
	//		if(!SysAuthenticate::isLogged()) {
	//			$request = SysRequest::cloneResource();
	//			// Register current link for user, if they finish redirect they to this page again!
	//			$_SESSION[__CUR_PAGE] = $request->getLink();
	//			$signupRes = new SiteResource ( "confirm" );
	//			RubikHelper::redirectToUrl($signupRes->getLink());
	//			exit;
	//		}
	//	}
	
		// Sure that isnot homepage. Redirect to over18 page if not confirm from it :D
		
		if(SysRequest::application() != 'users') {
			if(!SysAuthenticate::isLogged()) {
				//$signupRes = new SiteResource ( "confirm" );
				//RubikHelper::redirectToUrl($signupRes->getLink());
				$signupRes = new SiteResource ( "authenticate", 'login' );
				RubikHelper::redirectToUrl($signupRes->getLink());
				exit;
			} else {
				$userObj = SysAuthenticate::getAuthenticateObject();
				if($userObj->user_type != 'slivermember' && $userObj->user_type != 'goldmember') {
					// OK. Member not is puchase group, redirect
					$signupRes = new SiteResource ( "users", "membership" );
					RubikHelper::redirectToUrl($signupRes->getLink());
					exit;
				}
			}
		}
	}
}
//
//// Check if homepage, logout user
//if(SysRequest::application() == $config->defaultApp && SysAuthenticate::isLogged()) {
//	$signupRes = new SiteResource ( "authenticate", 'logout' );
//	RubikHelper::redirectToUrl($signupRes->getLink());
//	exit;
//}
